﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Management;

namespace web
{
    public partial class GetSystemID : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            GetMainHardDiskId();
        }

        public string GetCpuId()
        {
     
             ManagementClass mc = new ManagementClass("Win32_Processor");
             ManagementObjectCollection moc = mc.GetInstances();
             
             String strCpuID = null ;
             foreach( ManagementObject mo in moc )
             {
             strCpuID = mo.Properties["ProcessorId"].Value.ToString();
             break;
             }
             return strCpuID;
         
         }

        public string GetNetCardId()
        {

            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc2 = mc.GetInstances();
            string mcAddress = null;
            foreach(ManagementObject mo in moc2)
            {
                if((bool)mo["IPEnabled"] == true)
                mcAddress = "MAC addresst{0}"+mo["MacAddress"].ToString();
                mo.Dispose();
            }
            return mcAddress;
        }

        /// <summary>
        /// 获取主硬盘编号
        /// </summary>
        /// <returns></returns>
        public void GetMainHardDiskId()
        {

            String HDid;
            ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
            ManagementObjectCollection moc1 = cimobject1.GetInstances();
            foreach (ManagementObject mo in moc1)
            {
                HDid = (string)mo.Properties["Model"].Value;
                Response.Write("硬盘序列号：" + HDid.ToString());
            } 

        }
    }
}
